#include "GameItem.h"
#include "ConfigManager.h"

#define DROP_TIME 0.3

CGameItem::CGameItem()
{
}

CGameItem::~CGameItem()
{
}

bool CGameItem::init()
{
	if (!Node::init())
	{
		return false;
	}
	m_nType = T_Normal;

	m_pSprite = Sprite::create();
	this->addChild(m_pSprite);

	return true;
}

void CGameItem::refreshStyle()
{
	SpriteFrame* frame;
	if (m_pData->getSelection())
	{
		frame = SpriteFrameCache::getInstance()
			->getSpriteFrameByName(m_pData->getSelectPath());
	}
	else
	{
		frame = SpriteFrameCache::getInstance()
			->getSpriteFrameByName(getTypePath());
	}
	m_pSprite->setSpriteFrame(frame);
}

string CGameItem::getTypePath()
{
	switch (m_nType)
	{
	case Type::T_Normal:
		return	m_pData->getNormalPath();
		break;

	case Type::T_Line:
		return m_pData->getLinePath();
		break;
	case Type::T_Range:
		return m_pData->getRangePath();
		break;

	default:
		return m_pData->getNormalPath();
		break;
	}

}

void CGameItem::fallDown(int nCount)
{
	Size size = this->getContentSize();
	MoveBy* pMoveBy = MoveBy::create(DROP_TIME,
		Vec2(0, -nCount * size.height));

	this->runAction(pMoveBy);
}
